package com.ryan.encrypttool.business.auth.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ryan.encrypttool.business.auth.entity.po.UserRole;
import com.ryan.encrypttool.business.auth.service.UserRoleService;

/**
 * 用户角色表(UserRole)表控制层
 *
 * @author makejava
 * @since 2024-03-03 02:08:15
 */
@RestController
@RequestMapping("userRole")
public class UserRoleController {
    /**
     * 服务对象
     */
    @Resource
    private UserRoleService userRoleService;

    /**
     * 分页查询所有数据
     *
     * @param page 分页对象
     * @param userRole 查询实体
     * @return 所有数据
     */
    @GetMapping
    public Object selectAll(Page<UserRole> page, UserRole userRole) {
        return this.userRoleService.page(page, new QueryWrapper<>(userRole));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public Object selectOne(@PathVariable String id) {
        return this.userRoleService.getById(id);
    }

    /**
     * 新增数据
     *
     * @param userRole 实体对象
     * @return 新增结果
     */
    @PostMapping
    public Object insert(@RequestBody UserRole userRole) {
        return this.userRoleService.save(userRole);
    }

    /**
     * 修改数据
     *
     * @param userRole 实体对象
     * @return 修改结果
     */
    @PutMapping
    public Object update(@RequestBody UserRole userRole) {
        return this.userRoleService.updateById(userRole);
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @DeleteMapping
    public Object delete(@RequestParam("idList") List<Long> idList) {
        return this.userRoleService.removeByIds(idList);
    }
}
